import 'package:flutter/material.dart';
import './tabs/category.dart';
import './tabs/home.dart';
import './tabs/setting.dart';
import './tabs/user.dart';
import './tabs/message.dart';

class Tabs extends StatefulWidget {
  const Tabs({super.key});

  @override
  State<Tabs> createState() => _TabsState();
}

class _TabsState extends State<Tabs> {
  int _currentIndex = 0;
  final List<Widget> _pages = const [
    HomePage(),
    CategoryPage(),
    MessagePage(),
    SettingPage(),
    UserPage(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Flutter app"),
      ),
      drawer: const Drawer(
          child: Column(
        children: [
          Row(children: [
            Expanded(
                child: UserAccountsDrawerHeader(
                    accountName: Text("itying"),
                    accountEmail: Text("xxx@qq.com"),
                    currentAccountPicture: CircleAvatar(
                      backgroundImage: NetworkImage("https://www.itying.com/images/flutter/3.png"),
                    ),
                    otherAccountsPictures: [CircleAvatar(
                      backgroundImage: NetworkImage("https://www.itying.com/images/flutter/4.png"),
                    ), CircleAvatar(
                      backgroundImage: NetworkImage("https://www.itying.com/images/flutter/5.png"),
                    )],
                    decoration: BoxDecoration(
                        image: DecorationImage(
                            image: NetworkImage(
                                "https://www.itying.com/images/flutter/2.png"),
                            fit: BoxFit.cover))))
          ]),
          SizedBox(
            height: 60,
          ),
          ListTile(
            leading: CircleAvatar(child: Icon(Icons.people)),
            title: Text("个人中心"),
          ),
          Divider(),
          ListTile(
            leading: CircleAvatar(child: Icon(Icons.settings)),
            title: Text("系统设置"),
          ),
          Divider(),
        ],
      )),
      endDrawer: const Drawer(
        child: Column(
          children: [Text("右侧侧边栏")],
        ),
      ),
      body: _pages[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
          // iconSize: 35, // 底部菜单的大小
          fixedColor: Colors.red, // 选中的颜色
          currentIndex: _currentIndex, // 第几个菜单选中
          type: BottomNavigationBarType.fixed, // 底部有4个或4个以上需要配置参数
          onTap: (idx) {
            // // 点击菜单触发
            setState(() {
              _currentIndex = idx;
            });
          },
          items: const [
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
              label: "首页",
            ),
            BottomNavigationBarItem(icon: Icon(Icons.category), label: "分类"),
            BottomNavigationBarItem(icon: Icon(Icons.message), label: "消息"),
            BottomNavigationBarItem(icon: Icon(Icons.settings), label: "设置"),
            BottomNavigationBarItem(icon: Icon(Icons.people), label: "用户"),
          ]),
      floatingActionButton: Container(
          width: 60,
          height: 60,
          margin: const EdgeInsets.only(top: 5), // 调整位置
          child: FloatingActionButton(
            backgroundColor: _currentIndex == 2 ? Colors.red : Colors.yellow,
            onPressed: () {
              setState(() {
                _currentIndex = 2;
              });
            },
            shape: const CircleBorder(),
            child: const Icon(Icons.add),
          )),
      floatingActionButtonLocation:
          FloatingActionButtonLocation.centerDocked, // 浮动按钮位置
    );
  }
}
